import 'package:flutter/material.dart';
import 'package:flutter_play_android/ui/base/base_widget.dart';
import 'package:flutter_play_android/utils/toast_util.dart';

class PublishArticleScreen extends BaseWidget {
  const PublishArticleScreen({Key? key}) : super(key: key);

  @override
  BaseWidgetState<BaseWidget> attachState() => PublishArticleState();
}

class PublishArticleState extends BaseWidgetState<PublishArticleScreen> {
  @override
  void initState() {
    super.initState();
  }

  final FocusNode _titleFocusNode = FocusNode();
  final FocusNode _linkFocusNode = FocusNode();
  final TextEditingController _titleController = TextEditingController();
  final TextEditingController _linkController = TextEditingController();

  @override
  AppBar? attachAppBar() => AppBar(
        title: const Text("发布文章"),
        actions: [
          /*InkWell(
              onTap: () {
                var title = _titleController.text;
                var link = _linkController.text;
                ToastUtil.show(msg: "$title : $link");
              },
              child: Container(
                alignment: Alignment.center,
                padding: const EdgeInsets.all(10),
                child: const Text("分享"),
              )),*/
          IconButton(
              onPressed: () {
                var title = _titleController.text;
                var link = _linkController.text;
                ToastUtil.show(msg: "$title : $link");
              },
              icon: const Text(
                "分享",
                style: TextStyle(fontSize: 15, color: Colors.white),
              ))
        ],
      );

  @override
  Widget attachContentWidget(BuildContext context) {
    return Container(
      child: Column(
        children: [
          const Text(
            "文章标题",
            style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w600,
                color: Colors.black54),
          ),
          const SizedBox(
            height: 10,
          ),
          TextField(
            focusNode: _titleFocusNode,
            autofocus: false,
            controller: _titleController,
            decoration: const InputDecoration(
                contentPadding: EdgeInsets.all(5),
                hintText: "100字以内",
                border: OutlineInputBorder()),
            maxLines: 3,
            maxLength: 100,
          ),
          const SizedBox(
            height: 20,
          ),
          const Text(
            "文章连接",
            style: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w600,
                color: Colors.black54),
          ),
          const SizedBox(
            height: 10,
          ),
          TextField(
            focusNode: _linkFocusNode,
            autofocus: false,
            controller: _linkController,
            decoration: const InputDecoration(
              contentPadding: EdgeInsets.all(10),
              hintText: "例如：https://www.wanandroid.com",
              border: OutlineInputBorder(),
            ),
            maxLines: 5,
          ),
          Expanded(
            child: Container(
              alignment: Alignment.bottomLeft,
              child: const Text(
                "1. 只要是任何好文都可以分享哈，并不一定要是原创！投递的文章会进入广场 tab;"
                "\n2. CSDN，掘金，简书等官方博客站点会直接通过，不需要审核;"
                "\n3. 其他个人站点会进入审核阶段，不要投递任何无效链接，测试的请尽快删除，否则可能会对你的账号产生一定影响;"
                "\n4. 目前处于测试阶段，如果你发现500等错误，可以向我提交日志，让我们一起使网站变得更好。"
                "\n5. 由于本站只有我一个人开发与维护，会尽力保证24小时内审核，当然有可能哪天太累，会延期，请保持佛系...",
                style: TextStyle(fontSize: 12),
              ),
            ),
          )
        ],
      ),
      padding: const EdgeInsets.all(10),
    );
  }
}
